package com.zhl.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: z156940l@outlook.com
 * @Date: 2021/8/2 14:39
 */
@Getter
@AllArgsConstructor
public enum SystemEnums implements IEnum<Integer, String>{
    SUCCESS(10000,"success"),
    FAIL(10001,"fail"),
    SYSTEM_ERROR(10002, "系统错误"),
    SYSTEM_ROUTE_ERROR(10003, "联系管理员，微服务路径不正确"),
    SYSTEM_NOT_READY(10004, "系统暂时不可用，请稍后再试."),
    DATA_SAVING_FAILED(10005, "数据保存失败!"),
    DATA_DELETION_FAILED(10006, "数据删除失败!"),
    DATA_MODIFICATION_FAILED(10007, "数据修改失败!"),
    DATA_DOES_NOT_EXIST(10008, "修改失败,数据不存在!"),
    PARAMETER_VERIFICATION_FAILED(10009, "参数校验失败!"),
    SQL_BAD(100010, "sql错误异常"),
    REQUEST_METHOD_NOT_VALID(100011, "请求方式不正确"),
    ASSERT_ERROR(100012, "校验异常"),

    LOGIN_INVALID(20003, "用户登录失效，请重新登录"),
    TOKEN_VALID(20005, "token无效，请联系管理员"),
    ;

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 状态描述
     */
    private String msg;

    @Override
    public void setMsg(String msg) {
        this.msg = msg;
    }
    /**
     * 根据编码查找枚举
     *
     * @param code 编码
     * @return {@link SystemEnums } 实例
     **/
    public static SystemEnums find(String code) {
        for (SystemEnums instance : SystemEnums.values()) {
            if (instance.getCode().equals(code)) {
                return instance;
            }
        }
        return null;
    }
}
